package com.example.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

public class MainActivity extends AppCompatActivity {

    Button button,button2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);


        button = findViewById(R.id.frg_button1);
        button2 = findViewById(R.id.frg_button2);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 创建Fragment实例
                AnotherRightFragment fragment = new AnotherRightFragment();

                // 获取FragmentManager
                FragmentManager fragmentManager = getSupportFragmentManager();

                // 开始一个Fragment事务
                FragmentTransaction transaction = fragmentManager.beginTransaction();

                // 添加Fragment到Activity
//                transaction.add(R.id.right_layout, fragment);

                transaction.replace(R.id.right_layout,fragment);

                // 提交事务
                transaction.commit();
            }
        });






    }
}